import time
from selenium.webdriver.support.wait import WebDriverWait


class Base:
    # 初始化方法获取浏览器驱动
    def __init__(self, driver):
        self.driver = driver

    # 查找方法
    def base_find(self, loc, timeout=30, poll=1):
        return WebDriverWait(self.driver, timeout=timeout, poll_frequency=poll).\
            until(lambda x: x.find_element(*loc))

    # 点击方法
    def base_click(self, loc):
        self.base_find(loc).click()

    # 输入方法
    def base_input(self, loc, value):
        inputs = self.base_find(loc)
        inputs.clear()
        inputs.send_keys(value)

    # 获取文本/属性值方法
    def base_get_info(self, loc):
        # 返回文本
        return self.base_find(loc).text
        # 返回属性值
        # return self.base_find(loc).get_attribute("value")

    # 截图方法
    def base_get_screenshot(self):
        self.driver.get_screenshot_as_file("../image/{}.png".
                                           format(time.strftime("%Y_%m_%d %H_%M_%S")))
